/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package parih;

/**
 *
 * @author Drak_kin
 */
public class Chair {
     public int max_size;
    public Person whois[];
    public int count;
    public Chair(int size){
        max_size=size;
        whois=new Person[max_size];
        for (int i=0; i<size;++i) whois[i]=null;
        count=0;
   }
    public void Sit(Person who) throws Exception {
        if(count == max_size) 
            throw new Exception("Мест нет"); 
        else{
            whois[count]=who;
            count+=1;
        }
    }
    public boolean is_Free(){
        return count<max_size;
    }
    public void Leave(Person who) throws Exception{
        if (count == 0) throw new Exception("Данный человек не сидит");
        boolean is_here=false;
        for(int i=0; i<count ;++i){
            if (whois[i]==who){
                is_here=true;
                for(int j=i; j<count-1;++j){
                    whois[j]=whois[j+1];
                }
                --count;
                whois[count]=null;
                break;
            }
        }
        if(!is_here) throw new Exception("Данный человек не сидит");
    }
}
